package com.burstly.lib.downloadtracker;

import android.content.Context;
import com.burstly.lib.network.request.AbortableAsyncTask;
import com.burstly.lib.network.request.IRequestCallback;
import com.burstly.lib.util.LoggerExt;
import com.burstly.lib.util.Utils;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.List;
import org.apache.http.HttpHost;
import org.apache.http.HttpResponse;
import org.apache.http.StatusLine;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.utils.URLEncodedUtils;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;

public class TrackDownloadRequest extends AbortableAsyncTask<String>
{
  private static final String CONFIRM_DOWNLOAD_URI = "/scripts/ConfirmDownload.aspx";
  private static final LoggerExt LOG = LoggerExt.getInstance();
  private IRequestCallback<String> mCallback;
  private final WeakReference<Context> mContext;
  private final String mDeviceId;

  public TrackDownloadRequest(String paramString1, Context paramContext, String paramString2)
  {
    super("/scripts/ConfirmDownload.aspx", paramString1);
    this.mDeviceId = paramString2;
    this.mContext = new WeakReference(paramContext);
    setContentType("application/x-www-form-urlencoded");
  }

  private static UrlEncodedFormEntity createDataToPost(Context paramContext, String paramString)
    throws UnsupportedEncodingException
  {
    String str = fixIdentifier(paramString);
    ArrayList localArrayList = new ArrayList();
    DownloadTrackingBean localDownloadTrackingBean = new DownloadTrackingBean();
    localArrayList.add(new BasicNameValuePair("deviceId", str));
    localArrayList.add(new BasicNameValuePair("bundleId", Utils.getAppPackage(paramContext)));
    localDownloadTrackingBean.setBundleId(Utils.getAppPackage(paramContext));
    localArrayList.add(new BasicNameValuePair("version", localDownloadTrackingBean.getVersion()));
    localArrayList.add(new BasicNameValuePair("distribution", localDownloadTrackingBean.getDistribution().toString()));
    localArrayList.add(new BasicNameValuePair("host", localDownloadTrackingBean.getHost()));
    localArrayList.add(new BasicNameValuePair("token", localDownloadTrackingBean.calculateToken()));
    localArrayList.add(new BasicNameValuePair("encDevId", Utils.encryptedDeviceId(paramContext)));
    localArrayList.add(new BasicNameValuePair("encAndroidId", Utils.encryptedAndroidId(paramContext)));
    LoggerExt localLoggerExt = LOG;
    Object[] arrayOfObject = new Object[1];
    arrayOfObject[0] = URLEncodedUtils.format(localArrayList, "UTF-8");
    localLoggerExt.logDebug("BurstlyRequestTask", "Download track data to post is {0}", arrayOfObject);
    return new UrlEncodedFormEntity(localArrayList, "UTF-8");
  }

  private static String fixIdentifier(String paramString)
  {
    String str = paramString;
    if (str.length() % 2 != 0)
      str = str + "0";
    return str;
  }

  protected String convertServerResponse(String paramString)
  {
    if (this.mCallback != null)
      this.mCallback.onSuccessInBackground(paramString);
    this.mCallback = null;
    return paramString;
  }

  public IRequestCallback<String> getCallback()
  {
    return this.mCallback;
  }

  public void setCallback(IRequestCallback<String> paramIRequestCallback)
  {
    this.mCallback = paramIRequestCallback;
  }

  protected String tryToConnect(HttpHost paramHttpHost, HttpPost paramHttpPost)
  {
    Context localContext = (Context)this.mContext.get();
    if (localContext == null)
      return null;
    try
    {
      paramHttpPost.setEntity(createDataToPost(localContext, this.mDeviceId));
      localHttpResponse = Utils.makeRequest(paramHttpHost, paramHttpPost);
      int i = localHttpResponse.getStatusLine().getStatusCode();
      if (i != 200)
        throw new IOException("Status code is " + i + ", url: " + paramHttpHost);
    }
    catch (ClientProtocolException localClientProtocolException)
    {
      HttpResponse localHttpResponse;
      LOG.logError("BurstlyRequestTask", localClientProtocolException.getMessage(), new Object[0]);
      return null;
      String str = EntityUtils.toString(localHttpResponse.getEntity(), "UTF-8");
      LOG.logInfo("BurstlyRequestTask", "Download track result is {0}", new Object[] { str });
      return str;
    }
    catch (UnsupportedEncodingException localUnsupportedEncodingException)
    {
      while (true)
        LOG.logError("BurstlyRequestTask", localUnsupportedEncodingException.getMessage(), new Object[0]);
    }
    catch (IOException localIOException)
    {
      while (true)
        LOG.logError("BurstlyRequestTask", localIOException.getMessage(), new Object[0]);
    }
  }
}

/* Location:           E:\android\Toy Defense 2_dex2jar.jar
 * Qualified Name:     com.burstly.lib.downloadtracker.TrackDownloadRequest
 * JD-Core Version:    0.6.2
 */